package com.jiayang.hhotel.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jiayang.hhotel.R;
import com.jiayang.hhotel.bean.PrePayModel;

import java.util.List;

/**
 * Created by Administrator on 2017/5/25 0025.
 * 预付页面需要付款金额列表适配器
 */

public class PrePayListAdapter extends BaseAdapter {

    private Context t;
    private List<PrePayModel.PDepositListDtoBean> mList;
    private ViewHolder holder;

    public PrePayListAdapter(Context context, List<PrePayModel.PDepositListDtoBean> list){
        this.t = context;
        this.mList = list;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        PrePayModel.PDepositListDtoBean model=mList.get(position);
        if(convertView==null){
            convertView= LayoutInflater.from(t).inflate(R.layout.pre_pay_list_item,null);
            holder=new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        holder = (ViewHolder) convertView.getTag();
        holder.dateTime.setText(model.getDate());
        holder.type.setText(model.getComment1());
        holder.payMethod.setText(model.getTrnDescp());
        holder.money.setText(model.getAmount()+"");
        return convertView;
    }

    //获取总计金额
    public double getAmount(){
        double amount = 0.0;
        for (int i = 0;i<mList.size();i++){
            amount+=mList.get(i).getAmount();
        }
        return amount;
    }

    class ViewHolder{
        TextView dateTime;
        TextView type;
        TextView money;
        TextView payMethod;

        public ViewHolder(View item){
            dateTime= (TextView) item.findViewById(R.id.tv_date_time);
            type= (TextView) item.findViewById(R.id.tv_type);
            money= (TextView) item.findViewById(R.id.tv_money);
            payMethod= (TextView) item.findViewById(R.id.tv_method);
        }
    }
}
